<?php

namespace HelpDesk\Users\Controller;

use \Core\MVC\ModelMap;

class UserController {

    private $userDao;
    private $addSessionStorage;
    private $flashMessageStorage;

    public function index() {
        return new ModelMap("HelpDesk/Users/index", array(
            "users" => $this->userDao->getAll()
        ));
    }

    public function details($user) {
        return new ModelMap("HelpDesk/Users/details", array(
            "user" => $user
        ));
    }
    
    public function add() {
        $this->addSessionStorage->put("user", new \HelpDesk\Users\Model\User());
        return new ModelMap("redirect:UserController/addEdit");
    }
    
    public function addEdit() {
        return new ModelMap("HelpDesk/Users/add", array(
            "user" => $this->addSessionStorage->get("user"),
        ));
    }
    
    public function addEditPost() {
        $user = $this->addSessionStorage->get("user");
        $this->binder->bind($user);
        $this->addUserValidator->validate($user);
        $this->userDao->add($user);
        
        $this->flashMessageStorage->Add("helpdesk.users.add.success", $user);
        $this->addSessionStorage->clear();        
        return new ModelMap("redirect:UserController/details", $user); // TODO: REDIRECT TO SPECIFIC USER!
    }

    public function edit($user) {
        
    }

    public function remove($user) {
        
    }

    // ACCESS
    public function setUserDao($userDao) {
        $this->userDao = $userDao;
    }
    
    public function setAddSessionStorage($addSessionStorage) {
        $this->addSessionStorage = $addSessionStorage;
    }
    
    public function setFlashMessageStorage($flashMessageStorage) {
        $this->flashMessageStorage = $flashMessageStorage;
    }
}